import requests
import logging
class Tesryk():
    uid=""
    sid=""
    def setup_method(self):
        print("准备执行测试用例")
    def teardown_method(self):
        print("执行结束")
#登录账号参数正确并返回登录成功信息
    def test_login(self):
        try:
            url="http://10.59.9.18/small/user/v1/login"
            body={"phone":"13811033965","pwd":"123456Aa"}
            r=requests.post(url=url,json=body)
            logging.info(r.json())
            Tesryk.uid=r.json()["result"]["userId"]
            Tesryk.sid=r.json()["result"]["sessionId"]
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "13811033965"in r.json()
        assert ['json']== r.json()["phone"]["13811033965"]
#点击首页查看商品信息列表返回商品列表信息
    def test_commodityList(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/commodityList"
            r=requests.post(url=url)
            logging.info(r.json())
            Tesryk.uid=r.json()["result"]["userId"]
            Tesryk.sid=r.json()["result"]["sessionId"]
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
#点击商品查看商品详情并返回商品信息
    def test_findCommodityDetailsById(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/findCommodityDetailsById?commodityId:6"
            r=requests.post(url=url)
            logging.info(r.json())
            Tesryk.uid=r.json()["result"]["userId"]
            Tesryk.sid=r.json()["result"]["sessionId"]
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
#创建商品订单并返回商品信息
    def test_createOrder(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/createOrder"
            body={"commodityId”:5,”amount”:1","totalPrice""520.55,addressId:1"}
            r=requests.post(url=url,body=body)
            logging.info(r.json())
            Tesryk.uid=r.json()["result"]["userId"]
            Tesryk.sid=r.json()["result"]["sessionId"]
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "5"in r.json()
        assert ['json']== r.json()["commodityId"]["5"]
#根据订单状态查询订单信息并返回订单信息
    def test_findOrderListByStatus(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/findOrderListByStatus?status:1,page:1,count:5"
            r=requests.post(url=url)
            logging.info(r.json())
            Tesryk.uid=r.json()["result"]["userId"]
            Tesryk.sid=r.json()["result"]["sessionId"]
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
#支付一件商品并返回支付成功信息
    def test_pay(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/pay"
            body={"orderId":"1441165","payType":"1"}
            r=requests.post(url=url,body=body)
            logging.info(r.json())
            Tesryk.uid=r.json()["result"]["userId"]
            Tesryk.sid=r.json()["result"]["sessionId"]
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200
        assert "1441165"in r.json()
        assert ['json']== r.json()["orderId"]["1441165"]










